package com.kd.user.entity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Data
@Api("用户查询条件实体")
public class UserCondition {
    private static final Logger logger = LoggerFactory.getLogger(UserCondition.class);
    @ApiModelProperty(value = "用户名", name = "username")
    private String username;
    @ApiModelProperty(value = "名字", name = "name")
    private String name;
    @ApiModelProperty(value = "年龄", name = "age")
    private Integer age;
    @ApiModelProperty(value = "性别", name = "sex")
    private String sex;
    @ApiModelProperty(value = "生日开始", name = "birthdayStart")
    private Date birthdayStart;
    @ApiModelProperty(value = "创建日期开始", name = "createtimeStart")
    private Date createtimeStart;
    @ApiModelProperty(value = "生日结束", name = "birthdayEnd")
    private Date birthdayEnd;
    @ApiModelProperty(value = "创建日期结束", name = "createtimeEnd")
    private Date createtimeEnd;

    public String getCreatetimeStartStr() {
        SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
        String s="";
        if(createtimeStart!=null) {
            s = f.format(createtimeStart);}
        return s;
    }

    public void setCreatetimeStartStr(String createtimeStartStr) throws ParseException {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (createtimeStartStr != null && !"".equals(createtimeStartStr)) {
                this.createtimeStart = f.parse(createtimeStartStr);
            }
        } catch (ParseException e) {
            this.createtimeStart=f.parse("1990-01-01");
            logger.error("创建时间日期转换错误");
        }

    }

    public String getBirthdayStartStr() {
        SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
        String s="";
        if(birthdayStart!=null) {
            s = f.format(birthdayStart);}
        return s;
    }


    public void setbirthdayStartStr(String birthdayStartStr) throws ParseException {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (birthdayStartStr != null && !"".equals(birthdayStartStr)) {
                this.birthdayStart = f.parse(birthdayStartStr);
            }
        } catch (ParseException e) {
            this.birthdayStart=f.parse("1990-01-01");
            logger.error("生日日期转换错误");
        }
    }
    public String getCreatetimeEndStr() {
        SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
        String s="";
        if(createtimeEnd!=null) {
            s = f.format(createtimeEnd);}
        return s;
    }

    public void setCreatetimeEndStr(String createtimeEndStr) throws ParseException {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (createtimeEndStr != null && !"".equals(createtimeEndStr)) {
                this.createtimeEnd = f.parse(createtimeEndStr);
            }
        } catch (ParseException e) {
                this.createtimeEnd=f.parse("1990-01-01");
                logger.error("创建时间日期转换错误");
        }

    }

    public String getBirthdayEndStr() {
        SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
        String s="";
        if(birthdayEnd!=null) {
            s = f.format(birthdayEnd);}
        return s;
    }


    public void setbirthdayEndStr(String birthdayEndStr) throws ParseException {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (birthdayEndStr != null && !"".equals(birthdayEndStr)) {
                this.birthdayEnd = f.parse(birthdayEndStr);
            }
        } catch (ParseException e) {
            this.birthdayEnd=f.parse("1990-01-01");
            logger.error("生日日期转换错误");
        }
    }
}
